#!/bin/bash
dnf -y install pcs pacemaker fence-virt fence-agents corosync corosync-qdevice sbd 
cat << EOF >> /etc/hosts
10.211.55.33 ha1
10.211.55.35 ha2
EOF
cat << EOF >> /etc/corosync/corosync.conf
totem {
    version: 2
    cluster_name: hacluster
    crypto_cipher: none
    crypto_hash: none
}

logging {
    fileline: off
    to_stderr: yes
    to_logfile: yes
    logfile: /var/log/cluster/corosync.log
    to_syslog: yes
    debug: off

    logger_subsys {
        subsys: QUORUM
        debug: off
    }
}

quorum {
    provider: corosync_votequorum
    two_node: 1
}

nodelist {
    node {
        name: ha1
        nodeid: 1
        ring0_addr: 10.211.55.33
    }

    node {
        name: ha2
        nodeid: 2
        ring0_addr: 10.211.55.35
    }
}
EOF
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
cat << EOF >> /root/pwd
qwer1234
qwer1234
EOF
passwd hacluster < /root/pwd
systemctl start pcsd && systemctl enable pcsd
systemctl start pacemaker && systemctl enable pacemaker
systemctl start corosync && systemctl enable corosync
cat << EOF >> /root/hacluster
hacluster
qwer1234
EOF
pcs host auth ha1 ha2 < /root/hacluster
systemctl restart pacemaker
systemctl restart corosync
systemctl restart pcsd